using System.Collections;
using UnityEngine;

namespace EventBehaviorTree
{
    public class AsyncWorker
    {
        private IEnumerator _worker;
        private MonoBehaviour _coroutineStarter;
        public AsyncWorker(MonoBehaviour coroutineStarter) { _coroutineStarter = coroutineStarter; }
        
        public void Start() { _coroutineStarter.StartCoroutine(_worker); }

        public void ResetWorker(IEnumerator worker)
        {
            if (_worker != null)
            {
                _coroutineStarter.StopCoroutine(_worker);
                _worker = null;
            }
            _worker = worker;
        }
    }
}
